<?php
class Utils {

	public static $meses = array (
			'01' => 'Janeiro',
			'02' => 'Fevereiro',
			'03' => 'Março',
			'04' => 'Abril',
			'05' => 'Maio',
			'06' => 'Junho',
			'07' => 'Julho',
			'08' => 'Agosto',
			'09' => 'Setembro',
			'10' => 'Outubro',
			'11' => 'Novembro',
			'12' => 'Dezembro', );


	public static function findImageUrl($filename) {
		$string = YiiBase::getPathOfAlias('webroot').'/images/'.$filename;
		if ($filename != null && file_exists($string)) {
			return Yii::app()->request->baseUrl.'/images/'.$filename;
		} else {
			return Yii::app()->request->baseUrl.'/images/default_image.jpg';
		}
	}
	public static function hasContent($item) {
		return $item != null && !empty($item);
	}
	
	
	public static function findAllLessAdmin() {
		$list = User::model ()->findAll ( "type != :type", array (
				":type" => 'ADMINISTRATOR'
		) );
		return $list;
	}
	
	public static function findAllLessAdminAndUser() {
		$list = User::model ()->findAll ( "type != :type && id != :id", array (
			":type" => 'ADMINISTRATOR', ":id" => $_SESSION['user']->id,
		) );
		return $list;
	}

	public static function retornaAtualMes() {
		$mes = date('F');
		$mes_num = '';
		if($mes == "January"){
			$mes_num = "Janeiro";
		}elseif($mes == "February"){
			$mes_num = "Fevereiro";
		}elseif($mes == "March"){
			$mes_num = "Março";
		}elseif($mes == "April"){
			$mes_num = "Abril";
		}elseif($mes == "May"){
			$mes_num = "Maio";
		}elseif($mes == "June"){
			$mes_num = "Junho";
		} elseif($mes == "July") {
			$mes_num = "Julho";
		} elseif($mes == "August"){
			$mes_num = "Agosto";
		} elseif ($mes == "September") {
			$mes_num = "Setembro";
		} elseif ($mes == "October") {
			$mes_num = "Outubro";
		} elseif($mes == "November") {
			$mes_num = "Novembro";
		}else{
			$mes_num = "Dezembro";
		}

		return $mes_num;
	}
	
	public static function getProposalStatus($status) {
		$result = array();
		switch($status) {
			case Goal::$states['CREATED']:
				$result = array('color'=>'orange');
				break;
			case Goal::$states['CONFIRMED']:
				$result = array('color'=>'blue');
				break;
			case Goal::$states['FINISHED']:
				$result = array('color'=>'green');
				break;
			case Goal::$states['UNCOMPLETED']:
				$result = array('color'=>'black');
				break;
			case Goal::$states['UNAUTHORIZED']:
				$result = array('color'=>'red');
				break;
		}
		return $result;
	}
}